using System;
using ycx;

namespace RFS.Domain.PaiShi.Accounting
{
    public struct AccountPeriod
    {
        public AccountPeriod(DateTime beginDate=default, DateTime endDate=default)
        {
            beginDate = beginDate==default ? DateTime.Today.AddDays(-2) : beginDate.Date;
            endDate = (endDate-beginDate).TotalHours<24  ? beginDate.AddDays(1).AddSeconds(-1) : endDate.Date;
            
            BeginDate = beginDate;
            EndDate = endDate;
        }    
        
      
        public AccountPeriod(int daysAgo, int lastDays=1)
        {
            BeginDate =   DateTime.Today.AddDays(- daysAgo)  ;
            EndDate =   BeginDate .AddDays(lastDays).AddMinutes(-1) ;
        }

        public AccountPeriod(DateTime beginDate, int  lastDays )
        {
            BeginDate = beginDate==default ? DateTime.Today.AddDays(-2) : beginDate.Date;
            EndDate =   beginDate.AddDays(lastDays).AddMinutes(-1)  ;
            
        }
        public override string ToString()
        {
            return  $"{BeginDate.ToDateISO()}->{EndDate.ToDateISO()}";
        }

        public DateTime BeginDate { get; set; }
        public DateTime EndDate { get; set; }
    }
}